/**
 * 项目名称（软件名称）：忠旺机械物资管理系统(mms)
 * 研发设计单位：忠旺机械设备制造有限公司机械设计院智能控制设计科设计与研发。
 * 版权所有：忠旺机械设备制造有限公司
 * 注：本项目的一切技术专利，使用规范归解释权由忠旺机械设备制造有限公司所有。
 * 软件版本：Ver 1.0.0
 * 文件路径：com.zhongwang.mms.module.purchase.controller
 * 创建时间：2020年05月06日 18时04分
 **/
package com.zhongwang.mms.module.purchase.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.purchase.model.PurInvQueryModel;
import com.zhongwang.mms.module.purchase.model.proInv.PInventoryModel;
import com.zhongwang.mms.module.purchase.model.proInv.PProjectInventoryMarkModel;
import com.zhongwang.mms.module.purchase.service.PurProInvService;
import com.zhongwang.mms.util.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName： PurProInvController
 * @Description： 项目划库存控制层
 * @Author： 徐一贺
 * @Date： 2020/5/6 18:04
 * @Version： V1.0
 **/
@RequestMapping("/purchase/proInv")
@Controller
public class PurProInvController extends BaseController {
    @Autowired
    private PurProInvService purProInvService;

    @GetMapping("/index")
    /**
     *@FunctionName: index
     *@Description: 跳转到项目划库存首页
     *@Author: 徐一贺
     *@CreateDate: 2020/5/6 18:10
     *@Phone: 18241927380
     *@Param: []
     *@Return: java.lang.String
     *@Version: 1.0.0
     */
    public String index() {
        return "/purchase/purInvManage/proInv/page";
    }

    @GetMapping("/create")
    /**
     *@FunctionName: create
     *@Description: 跳转到新增项目划库存标记页面
     *@Author: 徐一贺
     *@CreateDate: 2020/5/6 19:22
     *@Phone: 18241927380
     *@Param: []
     *@Return: java.lang.String
     *@Version: 1.0.0
     */
    public String create() {
        return "/purchase/purInvManage/proInv/create/page";
    }
    @GetMapping("/execPage")
    /**
     *@FunctionName: execPage
     *@Description: 跳转到项目划库存执行页面
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 15:09
     *@Phone: 18241927380
     *@Param: []
     *@Return: java.lang.String
     *@Version: 1.0.0
     */
    public String execPage() {
        return "/purchase/purInvManage/proInv/exec/page";
    }
    /**
     *@FunctionName: execPage
     *@Description: 跳转到项目划库存执行页面
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 15:09
     *@Phone: 18241927380
     *@Param: []
     *@Return: java.lang.String
     *@Version: 1.0.0
     */
    @GetMapping("/execPage/{totalPrice}/{year}/{month}")
    public String execPageJump(Model model, @PathVariable("totalPrice") String totalPrice, @PathVariable("year") Integer year, @PathVariable("month") Integer month) {
        model.addAttribute("mode","index_exec");
        model.addAttribute("totalPrice",totalPrice);
        String start = DateUtil.getFirstDayOfMonth(month);
        start = start.replace(start.substring(0,start.indexOf("-")),year.toString());
        model.addAttribute("start",start.substring(0,10));
        String end = DateUtil.getLastDayOfMonth(month);
        end = end.replace(end.substring(0,end.indexOf("-")),year.toString());
        model.addAttribute("end",end.substring(0,10));
        return "/purchase/purInvManage/proInv/exec/page";
    }

    @PostMapping("/apply/list")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:view"})
    /**
     *@FunctionName: applyList
     *@Description: 获取项目划库存申请列表
     *@Author: 徐一贺
     *@CreateDate: 2020/5/6 18:26
     *@Phone: 18241927380
     *@Param: [param] 检索条件
     *@Return: com.zhongwang.mms.common.JsonResult 项目划库存申请列表
     *@Version: 1.0.0
     */
    public JsonResult applyList(PProjectInventoryMarkModel param) {
        startPage();
        List<PProjectInventoryMarkModel> list = purProInvService.applyList(param);
        return jsonResult(list);
    }
    @PostMapping("/review/list")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowarexec:view"})
    /**
     *@FunctionName: reviewList
     *@Description: 审核列表
     *@Author: 徐一贺
     *@CreateDate: 2020/5/6 18:26
     *@Phone: 18241927380
     *@Param: [param] 检索条件
     *@Return: com.zhongwang.mms.common.JsonResult 项目划库存申请列表
     *@Version: 1.0.0
     */
    public JsonResult reviewList(PProjectInventoryMarkModel param) {
        startPage();
        List<PProjectInventoryMarkModel> list = purProInvService.reviewList(param);
        return jsonResult(list);
    }

    @PostMapping("/apply/invList")
    @ResponseBody
    /**
     *@FunctionName: applyInvList
     *@Description: 获取新增项目划库存标记页面库存列表
     *@Author: 徐一贺
     *@CreateDate: 2020/5/6 19:34
     *@Phone: 18241927380
     *@Param: [param] 检索条件
     *@Return: com.zhongwang.mms.common.JsonResult 项目划库存标记页面库存列表
     *@Version: 1.0.0
     */
    public JsonResult applyInvList(PInventoryModel param) {
        startPage();
        List<PInventoryModel> list = purProInvService.applyInvList(param);
        return jsonResult(list);
    }

    @PostMapping("/apply/getInventory")
    @ResponseBody
    /**
     *@FunctionName: applyGetInventory
     *@Description: 根据主键和仓库类型获取库存信息
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 9:47
     *@Phone: 18241927380
     *@Param: [param.ityId] 主键、[param.ityType] p是外购件库，h是成品库，m是原料库
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applyGetInventory(PProjectInventoryMarkModel param) {
        PProjectInventoryMarkModel resultData = purProInvService.applyGetInventory(param);
        if (resultData == null) {
            return JsonResult.fail("获取库存信息失败！");
        }
        return JsonResult.success("", resultData);
    }

    @PostMapping("/apply/mark")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:edit"})
    /**
     *@FunctionName: applyMark
     *@Description: 创建标记
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 10:32
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applyMark(PProjectInventoryMarkModel param) {
        return purProInvService.applyMark(param);
    }

    @PostMapping("/apply/marks")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:edit"})
    /**
     *@FunctionName: applyMarks
     *@Description: 批量标记
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 11:26
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applyMarks(@RequestBody List<PProjectInventoryMarkModel> params) {
        return purProInvService.applyMarks(params);
    }
    @PostMapping("/apply/saveMark")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:edit"})
    /**
     *@FunctionName: applyMark
     *@Description: 编辑标记
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 10:32
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applySaveMarks(PProjectInventoryMarkModel param) {
        return purProInvService.applySaveMarks(param);
    }


    @PostMapping("/apply/remove")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:del"})
    /**
     *@FunctionName: applyRemove
     *@Description: 批量删除
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 13:26
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applyRemove(PProjectInventoryMarkModel param) {
        return purProInvService.applyRemove(param);
    }

    @PostMapping("/apply/submit")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowar:edit"})
    /**
     *@FunctionName: applySubmit
     *@Description: 批量提交
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 13:44
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applySubmit(PProjectInventoryMarkModel param) {
        return purProInvService.applySubmit(param);
    }

    @PostMapping("/apply/getPProjectInventoryMark")
    @ResponseBody
    /**
     *@FunctionName: applyGetPProjectInventoryMark
     *@Description: 根据主键获取项目化库存
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 14:16
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult applyGetPProjectInventoryMark(PProjectInventoryMarkModel param) {
        return purProInvService.getPProjectInventoryMark(param);
    }

    @PostMapping("/review/reject")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowarexec:edit"})
    /**
     *@FunctionName: reviewReject
     *@Description: 审核驳回
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 15:52
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult reviewReject(PProjectInventoryMarkModel param) {
        return purProInvService.reviewReject(param);
    }

    @PostMapping("/review/exec")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowarexec:edit"})
    /**
     *@FunctionName: reviewExec
     *@Description: 执行
     *@Author: 徐一贺
     *@CreateDate: 2020/5/8 16:38
     *@Phone: 18241927380
     *@Param: [param]
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult reviewExec(PProjectInventoryMarkModel param){
        return purProInvService.reviewExec(param);
    }

    @PostMapping("/review/revoke")
    @ResponseBody
    @RequiresPermissions({"purinv:purprowarexec:edit"})
    /**
     *@FunctionName: reviewRevoke
     *@Description: 撤销
     *@Author: 徐一贺
     *@CreateDate: 2020/5/9 8:31
     *@Phone: 18241927380
     *@Param: [param.pimIds] 被撤销的主键们
     *@Return: com.zhongwang.mms.common.JsonResult
     *@Version: 1.0.0
     */
    public JsonResult reviewRevoke(PProjectInventoryMarkModel param){
        return purProInvService.reviewRevoke(param);
    }

    @GetMapping("/exportExcel")
    @ResponseBody
    /**
     *@FunctionName: exportExcel
     *@Description: 导出项目化库存执行列表
     *@DesignIdea:
     *@Author: 徐一贺
     *@CreateDate: 2020/6/13 15:49
     *@Phone: 18241927380
     *@Param: [response, param]
     *@Return: void
     *@Throw:
     *@Version: v1.0.0
     */
    public void exportExcel(HttpServletResponse response, PProjectInventoryMarkModel param) {
        purProInvService.exportExcelReviewList(response,param);
    }
}